<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
	<title>初始页面</title>
	<script src="js/jquery.rem.min.js"></script>
	<script src="js/mui.min.js"></script>
	<script type="text/javascript" src="js/ajaxrequest.js"></script>
	<link href="css/mui.min.css" rel="stylesheet" />
	<script src="js/jquery.rem.min.js" type="text/javascript" charset="utf-8"></script>
	<script type="text/javascript" charset="utf-8">
			mui.init();
		</script>
</head>

<body>
<div class="TopDiv"></div>
<nav class="mui-bar mui-bar-tab">
	<a id="defaultTab" class="mui-tab-item mui-active" href="html/Make/MakeList.html">
				<span class="mui-icon" check="0" style="background:url(img/bottom_news1.png) no-repeat;background-size: 100%;">
				</span>
		<span class="mui-tab-label">阅读赚钱</span>
	</a>
	<a class="mui-tab-item" href="html/personal/earnMoney.html">
				<span class="mui-icon" check="1" style="background:url(img/bottom_task2.png) no-repeat;background-size: 100%;">
					<span style="display: none;" class="mui-badge">1</span></span>
		<span class="mui-tab-label">任务</span>
	</a>
	<a class="mui-tab-item" href="html/personal/personalIndex.html">
				<span class="mui-icon" check="2" style="background:url(img/bottom_my2.png) no-repeat;background-size: 100%;">
				</span>
		<span class="mui-tab-label">我的</span>
	</a>
</nav>
</body>
<style type="text/css">
		.mui-bar-tab {
			background: white;
			padding-top: 0.3rem;
			height: 2.608rem !important;
			box-shadow: 0px 1px 25.38px 1.62px rgba(222, 223, 224, 0.66);
		}
		
		.mui-active .mui-tab-label {
			color: #FC657C !important;
		}
		
		.mui-icon {
			margin-top: 0.434rem;
			margin-bottom: -0.2rem;
		}
		.IndexBom{
				position: fixed;
				width: 100%;
				bottom: 0px;
				height: 56px;
				background: rgba(0,0,0,0.7);
				z-index: 99;
		}
	</style>
<script type="text/javascript">
		mui.plusReady(function() {
			//判断是否是第一次登录参数
			//如果是第一次启动是没有vid的			
			if(!localStorage.logintoken){
				localStorage.logintoken=""
			}
			console.log(localStorage.logintoken)
			//调用安卓获取flag和invite_code			
//			plus.pluginutil.randomDeviceUUID(function( result ) {
//				localStorage.cid=result;
//			},null);//cid调用方法
//
//			plus.pluginutil.randomDeviceUUID(function( result ) {
//				localStorage.uuid=result;
//			},null);//uuid调用方法
//
//			plus.pluginutil.getYQM(function( result ) {
//				localStorage.invite_code=result;
//			},null);//invite_code调用方法
//			plus.pluginutil.getFlag(function( result ) {
//				localStorage.flag=result;
//			},null);//flag调用方法

			plus.pluginutil.getMsg(function( result ) {

				localStorage.invite_code=result[2];
				localStorage.flag=result[3];
				localStorage.cid=result[0];
				localStorage.uuid=result[1];
				setTimeout(function(){
					ajax()
				},1000)
			},null);//flag调用方法

//			localStorage.uuid="3dd067d7-3510-3916-848b-ff012de08f02";
//			localStorage.invite_code="2323423434";
//			localStorage.flag="1";
//			localStorage.cid="320";

			//整理思路
			function ajax(){
				$.ajax({
					type: "post",
					url: "http://120.76.201.26:8088/login/visitor",
					beforeSend: function(request) {
						request.setRequestHeader("Authorization", "Basic" + localStorage.logintoken);
					},
					async: true,
					data: {
						uuid: localStorage.uuid,
						cid: localStorage.cid,
						invite_code:localStorage.invite_code,//0代表没有邀请码
						flag:localStorage.flag,//1是游客2是用户
					},
					success: function(e) {
						console.log(e.code)
						console.log(e.vid)
						console.log(e.flag)
						localStorage.vid = e.data.vid;
						localStorage.flag = e.data.flag;
						if(localStorage.vid){
							ads()
						}
					}
				});
			}


		 	localStorage.showGuide=""
			window.addEventListener('newsId',function(event){
				  var id = event.detail.id;
				  //根据id向服务器请求新闻详情
				  if(id == "0"){
				  	 $(".TopDiv").addClass("IndexBom")
				  }else{
				  	 $(".TopDiv").removeClass("IndexBom")
				  }
				});
			//创建本地存储代码解释说明
			//			localStorage.uservid=""//游客id
			//			localStorage.logintoken=""//用户token
			//			localStorage.uuid=""//设备uuid
			//			localStorage.username=""//用户昵称
			//			localStorage.userimg=""//用户头像
			//			localStorage.balance=""//用户余额
			//			localStorage.today_total_rmb=""//今日收益
			//			localStorage.cid="360"//渠道名(暂时先这样，后期调用方法)
			//读取本地存储，检查是否为首次启动
			var showGuide = plus.storage.getItem("lauchFlag");
			//仅支持竖屏显示
			plus.screen.lockOrientation("portrait-primary");
			if(showGuide) {
				//有值，说明已经显示过了，无需显示；
				//关闭splash页面；
				f = 0;
				//启动过，判断是用户登录还是游客登录
//				if(localStorage.logintoken) {
//					userLogin();
//					console.log("用户登录")
//				} else {
//
//					visitorLogin();
//					console.log("游客登录")
//				}
				plus.navigator.closeSplashscreen();
				plus.navigator.setFullscreen(false);
			} else {
				//显示启动导航
				f = 1;
				//				mui.openWindow({
				//					id: 'index',
				//					url: 'index.html',
				//					styles: {
				//						popGesture: "none"
				//					},
				//					show: {
				//						aniShow: 'none'
				//					},
				//					waiting: {
				//						autoShow: false
				//					}
				//				});

				//				visitorLogin();
			}

			/*tab菜单切换*/



			function ads(){
				var subpage_style = {
					top: '0px',
					bottom: '51px'
				};
				var aniShow = {};
				var subpages = ['html/Make/MakeList.html', 'html/personal/earnMoney.html', 'html/personal/personalIndex.html'];
				//创建子页面，首个选项卡页面显示，其它均隐藏；
				var self = plus.webview.currentWebview();
				for(var i = 0; i < subpages.length; i++) {
					var temp = {};
					var sub = plus.webview.create(subpages[i], subpages[i], subpage_style);
					if(i > 0) {
						sub.hide();
					} else {
						temp[subpages[i]] = "true";
						mui.extend(aniShow, temp);
					}
					self.append(sub);
				}

				//当前激活选项
			var activeTab = subpages[0];
			//选项卡点击事件
			mui('.mui-bar-tab').on('tap', 'a', function(e) {
				var targetTab = this.getAttribute('href');
				if(targetTab == activeTab) {
					return;
				}
				//显示目标选项卡
				//若为iOS平台或非首次显示，则直接显示
				if(mui.os.ios || aniShow[targetTab]) {
					plus.webview.show(targetTab);
				} else {
					//否则，使用fade-in动画，且保存变量
					var temp = {};
					temp[targetTab] = "true";
					mui.extend(aniShow, temp);
					plus.webview.show(targetTab, "fade-in", 300);
				}
				//隐藏当前;
				plus.webview.hide(activeTab);
				//更改当前活跃的选项卡
				activeTab = targetTab;
				var index = this.querySelector('.mui-icon').getAttribute("check")
				if(index == 0) {
					$(".mui-icon").eq(0).css("background", "url(img/bottom_news1.png) no-repeat").css("background-size", "100%")
					$(".mui-icon").eq(1).css("background", "url(img/bottom_task2.png) no-repeat").css("background-size", "100%")
					$(".mui-icon").eq(2).css("background", "url(img/bottom_my2.png) no-repeat").css("background-size", "100%")
				} else if(index == 1) {
					$(".mui-icon").eq(1).css("background", "url(img/bottom_task1.png) no-repeat").css("background-size", "100%")
					$(".mui-icon").eq(0).css("background", "url(img/bottom_news2.png) no-repeat").css("background-size", "100%")
					$(".mui-icon").eq(2).css("background", "url(img/bottom_my2.png) no-repeat").css("background-size", "100%")
				} else {
					$(".mui-icon").eq(2).css("background", "url(img/bottom_my1.png) no-repeat").css("background-size", "100%")
					$(".mui-icon").eq(0).css("background", "url(img/bottom_news2.png) no-repeat").css("background-size", "100%")
					$(".mui-icon").eq(1).css("background", "url(img/bottom_task2.png) no-repeat").css("background-size", "100%")
				}
			});
			//自定义事件，模拟点击“首页选项卡”
			document.addEventListener('gohome', function() {
				var defaultTab = document.getElementById("defaultTab");
				//模拟首页点击
				mui.trigger(defaultTab, 'tap');
				//切换选项卡高亮
				var current = document.querySelector(".mui-bar-tab>.mui-tab-item.mui-active");
				if(defaultTab !== current) {
					current.classList.remove('mui-active');
					defaultTab.classList.add('mui-active');
				}
			});

			}





			
		});

	</script>

</html>